package com.yixun.qfbao.druid.filter.config;

import com.alibaba.druid.filter.config.ConfigTools;
import com.alibaba.druid.pool.DruidDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SecurityDataSource extends DruidDataSource{
    private static Logger logger= LoggerFactory.getLogger(SecurityDataSource.class);
    @Override
    public void setUsername(String username) {
        try {
            username = ConfigTools.decrypt(username);
        } catch (Exception e) {
            logger.error("setUsername: {}, error: ", username, e);
        }
        super.setUsername(username);
    }

    @Override
    public void setPassword(String password) {
        try {
            password = ConfigTools.decrypt(password);
        } catch (Exception e) {
            logger.error("setPassword: {}, error: {}", password, e);
        }
        super.setPassword(password);
    }

    public static void main(String[] args) throws Exception {
        String username = "root";
        String password = "";
        System.out.println("加密后的password = [" + ConfigTools.encrypt(password) + "]");
        System.out.println("加密后的username = [" + ConfigTools.encrypt(username) + "]");
    }
}
